﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using StudentManage.Data;

namespace StudentManage.Web.Admin.Management.TypeManage
{
    public partial class ProjectTypeEdit : SecurityPage
    {
        private void LoadData()
        {
            string EditId = Request.QueryString["EditId"].ToString();
            TypeInfo md = TypeInfo.Where("id=@0", int.Parse(EditId)).First();
            this.txt_TypeName.Text = md.TypeName;
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack) return;
            if (Request.QueryString["EditId"] != null)
                this.LoadData();
        }

        protected void Btn_Save_Click(object sender, EventArgs e)
        {
            string TypeId = Request.QueryString["TypeId"].ToString();

            TypeInfo md;
            if (Request.QueryString["EditId"] == null)
            {
                md = new TypeInfo();
            }
            else
            {
                md = TypeInfo.Where("id=@0", int.Parse(Request.QueryString["EditId"].ToString())).First();
            }

            md.TypeName = this.txt_TypeName.Text.Trim();
            md.IsDel = false;
            md.ProjectTypeid = int.Parse(TypeId);
            md.AddTime = DateTime.Now;
            md.Parentid = 0;
            if (Request.QueryString["EditId"] == null)
            {
                TypeInfo.Insert(md);
            }
            else
            {
                TypeInfo.Update(md, "id=@0", int.Parse(Request.QueryString["EditId"].ToString()));
            }

            Response.Redirect("ProjectTypeList.aspx?TypeId=" + TypeId);
        }

        protected void Btn_Return_Click(object sender, EventArgs e)
        {
            string TypeId = Request.QueryString["TypeId"].ToString();
            Response.Redirect("ProjectTypeList.aspx?TypeId=" + TypeId);
        }
    }
}